﻿using System;
using System.Collections.Generic;
using System.Text;
using PostSharp.Aspects.Dependencies;

namespace Arcana.Contract.Property.Is.Not.LowerEqual
{
    /// <summary>
    /// A contract that checks if a property is not lower than or equal to a given value.
    /// </summary>
    [Serializable]
    [AspectRoleDependency(AspectDependencyAction.Commute, Roles.Conditional)]
    [ProvideAspectRole(Roles.Contract)]
    [ProvideAspectRole(Roles.Property)]
    [ProvideAspectRole(Roles.Conditional)]
    public sealed class ThanAttribute : ComparingContractBase
    {
        private object _value;

        /// <summary>
        /// Initializes a new instance of <b>Property.Is.Not.LowerEqual.Than</b> contract.
        /// </summary>
        /// <param name="value">The value used for comparison.</param>
        public ThanAttribute(object value)
        {
            _value = value;
        }

        /// <summary>
        /// Performs validation on the property.
        /// </summary>
        /// <param name="property">The property that should be validated.</param>
        /// <returns><b>true</b> if <i>property</i> is validated, otherwise <b>false</b>.</returns>
        protected override bool ValidateProperty(object property)
        {
            return !(Comparer.Compare(property, _value) <= 0);
        }
    }
}
